<?php

require_once(FWS_DIR_LIB.'core/ModelAndView.class.php');
require_once(FWS_DIR_MODEL_DAO.'teammodeldao.class.php');
require_once(FWS_DIR_MODEL.'teammodel.class.php');
require_once(FWS_DIR_MODEL_DAO.'clubmodeldao.class.php');
require_once(FWS_DIR_MODEL.'clubmodel.class.php');

class TeamMultiActionController {

	var $_teammodeldao;
	var $_clubmodeldao;

	function TeamMultiActionController() {
		$this->_teammodeldao = new TeamModelDao();
		$this->_clubmodeldao = new ClubModelDao();
		mysql_connect(FWS_DBDOMAIN,FWS_DBUSER,FWS_DBPASS) or exit(mysql_error());
		mysql_select_db(FWS_DBNAME) or exit(mysql_error());		
	}

	function list_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0, $this->_teammodeldao->findAllTeam());
		mysql_close();		
		$mv->setView('list_team.tpl');
		return $mv;
	}
	
	function profile_action() {
		$mv = new ModelAndView();
		$mv->setModel($this->_teammodeldao->queryTeamById($_GET[GLOBAL_PARAM_IDTEAM]));
		mysql_close();		
		$mv->setView('profile_team.tpl');
		//$mv->setView('debug.tpl');
		return $mv;
	}

	function addform_action() {
		$mv = new ModelAndView();
		mysql_close();		
		$mv->setView('team_insertform.tpl');
		return $mv;
	}
	
	function updateForm_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0, $this->_teammodeldao->queryTeamById($_GET[GLOBAL_PARAM_IDTEAM]));
		$mv->addToModel(1, $this->_clubmodeldao->findRefClub());
		mysql_close();		
		$mv->setView('team_updateform.tpl');
		return $mv;
	}
	
	function update_action() {
		$mv = new ModelAndView();
		$this->_teammodeldao->updateTeam(new TeamModel($_POST));
		//mysql_close();		
		return $this->list_action();
	}
	
	function insertForm_action() {
		$mv = new ModelAndView();
		$mv->addToModel(0, $this->_clubmodeldao->findRefClub());
		mysql_close();		
		$mv->setView('team_insertform.tpl');
		return $mv;
	}
	
	
}

?>